package com.yztc.orangeentertainment.ui.main.findfragment.findmodel;

import com.yztc.orangeentertainment.bean.findbean.SearchBean;
import com.yztc.orangeentertainment.bean.findbean.SearchDataBean;
import com.yztc.orangeentertainment.bean.findbean.SearchListBean;
import com.yztc.orangeentertainment.ui.main.findfragment.findutils.FindConstant;

import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by My on 2016/10/8.
 */
public class SearchModle implements ISearchModle {

    @Override
    public void LoadSearchData(String type, Map<String, String> map, final OnLoadSearchListener
            loadSearchListener) {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(FindConstant.FindPath.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Call<SearchBean> call = retrofit.create(RetrofitService.class).getSearchAll(type, map);
        call.enqueue(new Callback<SearchBean>() {
            @Override
            public void onResponse(Call<SearchBean> call, Response<SearchBean> response) {
                SearchBean searchBean = response.body();
                SearchDataBean searchDataBean = searchBean.getData();
                List<SearchListBean> searchListBeens = searchDataBean.getList();
                loadSearchListener.getSearchListBeanList(searchListBeens);
            }

            @Override
            public void onFailure(Call<SearchBean> call, Throwable t) {
                loadSearchListener.onFailure((Exception) t);
            }
        });
    }
}
